"""
@name : 练习01
@author : wenyao
@projectname: xsfh
"""
# 1、a+=c，a=a+c区别是什么？
#对于不可变数据类型是没有区别的，
#对于可变数据类型a+=c不会创建新的对象，a=a+c会创建新的对象
# 2、列表去重并从大到小排序？
# lst = [3,3,2,1,4,6]
# lst2 = list(set(lst))
# lst2.sort(reverse=True)
# print(lst2)
# 3、如何在一个函数内部修改全局变量
# global 关键字
# 4、如何跨模块共享全局变量
#创建管理全局变量的模块（配置文件），通过导入的方式共享全局变量
# 5、python基本数据类型有哪些
#字符串、整型、布尔类型、列表、元组、字典、集合
# 6、python中生成随机整数（1-10）、随机小数（1-10）， 0-1之间的方法
## import random
# print(random.randint(1,10))
# print(random.uniform(1,10))
# print(random.random())
# 7、python中哪些是可变数据类型，哪些是不可变数类型
#可变： 列表、字典、集合
#不可变：字符串、元组、数值类型
# 8、如何判断一个字符串是否是回文（从左至右，从右至左）都一样
# str1 == str1[::-1]
# 9、将两个列表[11,-2,4,5,8]和[5,2,-10,0]合并成一个列表，并且从小到大排序
# a = [11,-2,4,5,8]
# b = [5,2,-10,0]
# print(sorted(a + b))
# 10、提取给定log日志里的ip和时间字段，将时间格式转化为“2021-07-16 10:00:00”此类型字符串

line = '175.8.134.46 - - [04/Jun/2021:13:57:00 +0800] "GET /download HTTP/1.1" 404 82 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"'
import re
import time
line = re.sub(r'[\[\]]', '', line)
line = line.replace("[","")
solo = line.split()
print(solo)
# 把字符串转化为时间对象
t = time.strptime(solo[3], "%d/%b/%Y:%H:%M:%S")
#把时间对象转化为字符串
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", t)
print(otherStyleTime)


fp = open("log2.txt","w+")
with open("scwebsite2_ssl.log") as log:
    for line in log:
        line = re.sub(r'[\[\]]', '', line)
        solo = line.split()
        fp.write(f"{solo[0]} ")
        t = time.strptime(solo[3],"%d/%b/%Y:%H:%M:%S")
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S",t)
        print(otherStyleTime)
        fp.write(f"{otherStyleTime}\n")


# a = [1,2,3,4,5]
# print(a[5])
# import math
# math.xxx()
# suda = {'a':1,'b':2}
# # suda["c"]
# int ("abc")

# assert 0>1

# try:
#     print("start try......")
#     a = 1/0
#     print("end try.......")
# except ZeroDivisionError as ie:
#     print("index error:",ie)
# except ZeroDivisionError as ze:
#     print("zero error:",ze)
# except Exception as e:
#     print("exception error:",e)
# print("ending......")

# try:
#     grade = input("请输入你的成绩:")
#     b = int(grade)
#     assert b >= 0 and b <= 100
# except ValueError as ve:
#     print("输入错误，请确保输入的是一个整数")
# except AssertionError as ae:
#     print("输入错误，请确保输入的范围在[1,100]")
# else:
#     print("输入正确")


# try:
#     grade = input("请输入你的成绩：")
#     a = int(grade)
#     assert a >= 0 and a <=100
# except ValueError as ve:
#     print("输入错误，请确保输入的成绩是一个整数")
# except AssertionError as ae:
#     print("输入错误，请确保输入的成绩在[0,100]之间")
# else:
#     print(f"输入正确，你的成绩为{grade}分")








